set the textFont of field "zipHole" to "Helvetica"
set the textSize of field "zipHole" to 18
put EMPTY into field "zipHole"
put "Enter a five digit zip code." into field "displayResults"
end
on checkKey
set x to charToNum(the key)
if ((x < 48) or (x > 57)) and (x <> 8) then
dontPassEvent()
end if
if (length(field "zipHole") = 5) and (x <> 8) then
dontPassEvent()
end if
end
on checkFieldLength
if length(field "zipHole") = 5 then
go("sea")
end if
end
on searchAndReport
global index, zip, foist
set foist to 1
put EMPTY into field "displayResults"
if length(field "zipHole") < 5 then
put "Please enter five digits and press return." into field "displayResults"
put EMPTY into field "zipHole"
else
put "Let me look up zip code" && field "zipHole" & "." & RETURN & "Back in a flash!" into field "displayResults"
set zip to field "zipHole"
set xx to char 1 to 2 of field "zipHole"
set flag to 0
set index to 1
repeat while line index of field xx <> EMPTY
if line index of field xx contains zip then
report(xx)
set flag to 1
end if
set index to index + 5
end repeat
set xy to string(value(xx) - 1)
if value(xy) < 0 then
set xy to "00"
end if
if length(xy) < 2 then
put "0" before xy
end if
set index to 1
repeat while line index of field xy <> EMPTY
if line index of field xy contains zip then
report(xy)
set flag to 1
end if
set index to index + 5
end repeat
set xz to string(value(xx) - 2)
if value(xz) < 0 then
set xz to "00"
end if
if length(xz) < 2 then
put "0" before xz
end if
set index to 1
repeat while line index of field xz <> EMPTY
if line index of field xz contains zip then
report(xz)
set flag to 1
end if
set index to index + 5
end repeat
if flag = 0 then
put "To locate a dealer near you:" & RETURN & "Call 1-800-GO-TOYOTA!" into field "displayResults"
else
put RETURN after field "displayResults"
end if
put EMPTY into field "zipHole"
end if
end
on report zz
global index, zip, foist
if foist = 1 then
put "The Toyota Dealer(s) nearest to zip code" && zip && "is(are):" & RETURN into field "displayResults"
end if
put RETURN & line index + 1 of field zz & RETURN & line index + 2 of field zz & RETURN after field "displayResults"
put word 1 to 3 of line index + 3 of field zz after field "displayResults"
set x to charToNum(char 1 of word 3 of line index + 3 of field zz)
if (x < 48) or (x > 57) then
put " " & word 4 of line index + 3 of field zz after field "displayResults"
end if
set x to charToNum(char 1 of word 4 of line index + 3 of field zz)
if (x < 48) or (x > 57) then
put " " & word 5 of line index + 3 of field zz after field "displayResults"
end if
set x to charToNum(char 1 of word 5 of line index + 3 of field zz)
if (x < 48) or (x > 57) then
put " " & word 6 of line index + 3 of field zz after field "displayResults"
end if
set x to charToNum(char 1 of word 6 of line index + 3 of field zz)
if (x < 48) or (x > 57) then
put " " & word 7 of line index + 3 of field zz after field "displayResults"
end if
put RETURN & "(" & char 1 to 3 of line index + 4 of field zz & ") " & char 4 to 6 of line index + 4 of field zz & "-" & char 7 to 10 of line index + 4 of field zz & RETURN after field "displayResults"